package hotel.modal;

import hotel.dao.RoomTypeDao;
import javafx.beans.property.*;

public class RoomType {
	private SimpleIntegerProperty typeId;		// 房间类型编号
	private SimpleStringProperty typeName;		// 房间类型名称
	private SimpleBooleanProperty hourRoom;		// 是否钟点房
	private SimpleIntegerProperty bedNum;		// 床位数量
	private SimpleDoubleProperty deposit;		// 押金
	private SimpleDoubleProperty price;			// 单价
	private SimpleBooleanProperty modified; 
	
	private void init(RoomTypeDao rt) {
		if(rt != null) {
			this.typeId = new SimpleIntegerProperty(rt.getTypeId());
			this.typeName = new SimpleStringProperty(rt.getTypeName());
			this.hourRoom = new SimpleBooleanProperty(rt.isHourRoom());
			this.bedNum = new SimpleIntegerProperty(rt.getBedNum());
			this.deposit = new SimpleDoubleProperty(rt.getDeposit());
			this.price = new SimpleDoubleProperty(rt.getPrice());
		}else {
			this.typeId = new SimpleIntegerProperty(0);
			this.typeName = new SimpleStringProperty("");
			this.hourRoom = new SimpleBooleanProperty(false);
			this.bedNum = new SimpleIntegerProperty(1);
			this.deposit = new SimpleDoubleProperty(0);
			this.price = new SimpleDoubleProperty(0);
		}
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public RoomType(RoomTypeDao rt) {	
		init(rt);
	}
	
	public Object getDao() {
		RoomTypeDao rt = new RoomTypeDao();
		rt.setTypeId(typeId.get());
		rt.setTypeName(typeName.get());
		rt.setHourRoom(hourRoom.get());
		rt.setBedNum(bedNum.get());
		rt.setDeposit(deposit.get());
		rt.setPrice(price.get());
		return rt;
	}
	
	public RoomType() {
		init(null);
	}
	
	public RoomType(RoomType roomType) {	// 复制构造方法
		this.typeId = new SimpleIntegerProperty(roomType.getTypeId());
		this.typeName = new SimpleStringProperty(roomType.getTypeName());
		this.hourRoom = new SimpleBooleanProperty(roomType.isHourRoom());
		this.bedNum = new SimpleIntegerProperty(roomType.getBedNum());
		this.deposit = new SimpleDoubleProperty(roomType.getDeposit());
		this.price = new SimpleDoubleProperty(roomType.getPrice());
		this.modified = new SimpleBooleanProperty(roomType.isModified());
	}
	
	public RoomType(int typeId, String typeName, int hourRoom, int bedNum, double deposit, double price) {
		this.typeId = new SimpleIntegerProperty(typeId);
		this.typeName = new SimpleStringProperty(typeName);
		if(hourRoom > 0) this.hourRoom = new SimpleBooleanProperty(true);
		else this.hourRoom = new SimpleBooleanProperty(false);
		this.bedNum = new SimpleIntegerProperty(bedNum);
		this.deposit = new SimpleDoubleProperty(deposit);
		this.price = new SimpleDoubleProperty(price);
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public RoomType(SimpleIntegerProperty typeId, SimpleStringProperty typeName, SimpleBooleanProperty hourRoom,
			SimpleIntegerProperty bedNum, SimpleDoubleProperty deposit, SimpleDoubleProperty price) {
		super();
		this.typeId = typeId;
		this.typeName = typeName;
		this.hourRoom = hourRoom;
		this.bedNum = bedNum;
		this.deposit = deposit;
		this.price = price;
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public final SimpleIntegerProperty typeIdProperty() {
		return this.typeId;
	}
	
	
	public final int getTypeId() {
		return this.typeIdProperty().get();
	}
	
	public final void setTypeId(final int typeId) {
		this.typeIdProperty().set(typeId);
	}
	
	public final SimpleStringProperty typeNameProperty() {
		return this.typeName;
	}
	
	public final String getTypeName() {
		return this.typeNameProperty().get();
	}
	
	public final void setTypeName(final String typeName) {
		this.typeNameProperty().set(typeName);
	}
	
	public final SimpleBooleanProperty hourRoomProperty() {
		return this.hourRoom;
	}
	
	public final boolean isHourRoom() {
		return this.hourRoomProperty().get();
	}
	
	public final void setHourRoom(final boolean hourRoom) {
		this.hourRoomProperty().set(hourRoom);
	}
	
	public final SimpleIntegerProperty bedNumProperty() {
		return this.bedNum;
	}
	
	public final int getBedNum() {
		return this.bedNumProperty().get();
	}
	
	public final void setBedNum(final int bedNum) {
		this.bedNumProperty().set(bedNum);
	}
	
	public final SimpleDoubleProperty depositProperty() {
		return this.deposit;
	}
	
	public final double getDeposit() {
		return this.depositProperty().get();
	}
	
	public final void setDeposit(final double deposit) {
		this.depositProperty().set(deposit);
	}
	
	public final SimpleDoubleProperty priceProperty() {
		return this.price;
	}
	
	public final double getPrice() {
		return this.priceProperty().get();
	}
	
	public final void setPrice(final double price) {
		this.priceProperty().set(price);
	}
	
	public String toString() {
		String str = String.format("TypeID=%d  TypeName='%s'  HourRoom='%s' BedNum=%d  Deposit=%.2f  Price=%.2f" , 
				this.getTypeId(), this.getTypeName(), (this.isHourRoom()?"是":"否"), this.getBedNum(), this.getDeposit(),
				this.getPrice());
		return str;
	}

	public final SimpleBooleanProperty modifiedProperty() {
		return this.modified;
	}
	

	public final boolean isModified() {
		return this.modifiedProperty().get();
	}
	

	public final void setModified(final boolean modified) {
		this.modifiedProperty().set(modified);
	}
	
}
